<?php
declare (strict_types = 1);

namespace app\shop\controller;

use app\common\service\GoodsService\GoodsService;
use app\Normal;
use think\annotation\Route;
use think\annotation\route\Group;
use think\annotation\route\Middleware;

/**
 * @Group("Goods")
 * @Middleware({shopMiddileware::class})
 */
class Goods extends \app\BaseShopController
{
    /**
     * 编辑销量配置
     * @Route("Fictitious",method="POST")
     * @return void
     */
    public function Fictitious(){
        $result = callApi(GoodsService::class, 'Fictitious',$this->_all_data);
        if($result['code'] == Normal::SUC){
            $this->log(['content'=>'修改销量配置','request_param'=> json_encode($this->_all_data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }
    /**
     * 获取商品列表分页
     * @Route("getGoodsListByPage",method="GET")
     * @return void
     */
    public function getGoodsListByPage(){
        $result = callApi(GoodsService::class, 'goodsList',$this->_all_data);
        return apiResponse($result);
    }
    /**
     * 获取商品列表分页
     * @Route("getGoodsDetail/:id",method="GET")
     * @return void
     */
    public function getGoodsDetail($id){
        $param=[
            'id'=>$id,
            'cid'=> $this->_master_user['cid'],
            'cb_id'=> $this->_master_user['cb_id']
        ];
        $result = callApi(GoodsService::class, 'getGoodsDetail',$param);
        return apiResponse($result);
    }
    /**
     * 设置运费模板
     * @Route("setTemplate",method="POST")
     * @return void
     */
    public function setTemplate(){
        $result = callApi(GoodsService::class, 'set_template',$this->_all_data);
        if($result['code'] == Normal::SUC){
            $this->log(['content'=>'设置运费模板','request_param'=> json_encode($this->_all_data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }
    /**
     * 设置商品服务
     * @Route("setService",method="POST")
     * @return void
     */
    public function setService(){
        $result = callApi(GoodsService::class, 'setService',$this->_all_data);
        if($result['code'] == Normal::SUC){
            $this->log(['content'=>'设置商品服务','request_param'=> json_encode($this->_all_data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }
    /**
     * 设置商品服务
     * @Route("upDownGoods",method="POST")
     * @return void
     */
    public function upDownGoods(){
        $result = callApi(GoodsService::class, 'upDownGoods',$this->_all_data);
        if($result['code'] == Normal::SUC){
            $this->log(['content'=>'设置商品上下架','request_param'=> json_encode($this->_all_data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }
    /**
     * 批量上下架
     * @Route("upDownGoodsMany",method="POST")
     * @return void
     */
    public function upDownGoodsMany(){
        $result = callApi(GoodsService::class, 'upDownGoodsMany',$this->_all_data);
        if($result['code'] == Normal::SUC){
            $this->log(['content'=>'商品批量上下架','request_param'=> json_encode($this->_all_data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }
    
    /**
     * 修改商品
     * @Route("editGoods",method="PUT")
     * @return void
     */
    public function editGoods(){
        $result = callApi(GoodsService::class, 'editGoods',$this->_all_data);
        if($result['code'] == Normal::SUC){
            $this->log(['content'=>'修改商品','request_param'=> json_encode($this->_all_data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }
}